package org.example.service.impl;

import lombok.extern.slf4j.Slf4j;
import org.example.bean.ProductBean;
import org.example.bean.UserEntity;
import org.example.dao.UserMapper;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    public List findLimit(int start, int pageSize) {
        return userMapper.findLimit(start, pageSize);
    }

    @Override
    public void batchInsert(UserEntity userEntity) {
        long start = System.currentTimeMillis();
        List<UserEntity> list = userMapper.queryList();
        System.out.println("queryList耗时="+(System.currentTimeMillis() - start));

        long start2 = System.currentTimeMillis();
        List<UserEntity> branchList = null;
        /*for(int i=0; i<10; i++){
            if(i==0){
                branchList = list.subList(0, i*5000+5000);
            }else{
                branchList = list.subList(5000*i+1, i*5000+5000);
            }
            userMapper.batchInsert(branchList);
        }*/
        /*for(int i=0; i<1000; i++){
            if(i==0){
                branchList = list.subList(0, i*50+50);
            }else{
                branchList = list.subList(50*i+1, i*50+50);
            }
            userMapper.batchInsert(branchList);
        }*/
        /*for(int i=0; i<5000; i++){
            if(i==0){
                branchList = list.subList(0, i*10+10);
            }else{
                branchList = list.subList(10*i+1, i*10+10);
            }
            userMapper.batchInsert(branchList);
        }*/
        for(int i=0; i<50; i++){
            if(i==0){
                branchList = list.subList(0, i*1000+1000);
            }else{
                branchList = list.subList(1000*i+1, i*1000+1000);
            }
            userMapper.batchInsert(branchList);
        }

        System.out.println("batchInsert耗时="+(System.currentTimeMillis() - start2));
    }
}
